package asm.api;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;

import java.io.File;
import java.io.FileOutputStream;

public class Main {
    public static void main(String[] args) throws Exception {
        //读取
        //ClassReader：用于读取已经编译好的.class文件
        ClassReader classReader = new ClassReader("asm/Base");
        //用于重新构建编译后的类，如修改类名、属性以及方法，也可以生成新的类的字节码文件
        ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        //处理
        ClassVisitor classVisitor = new MyClassVisitor(classWriter);
        classReader.accept(classVisitor, ClassReader.SKIP_DEBUG);
        byte[] data = classWriter.toByteArray();
        //输出
        File f = new File("C:\\Users\\jinbin\\Code\\exp\\src\\main\\java\\asm\\api\\Base.java");
        FileOutputStream fout = new FileOutputStream(f);
        fout.write(data);
        fout.close();
        System.out.println("now generator cc success!!!!!");
    }
}
